﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GP.Logic;
using GP.Logic.Model;

namespace WebForms.Doctor
{
    public partial class events : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DoctorService doc = new DoctorService();
                Citizen currentCitizen = doc.GetCitizen();

                if (currentCitizen == null)
                {
                    Response.Redirect("/Doctor/", true);
                    return;
                }
                // CitizenIDValue.Text = currentCitizen.CitizenId.ToString();

                GP.Logic.Model.Doctor doctor = doc.GetDoctor();
                DocNameValue.Text = doctor.Name;

                primaryDoctor.Text = currentCitizen.Doctor.Name;
                SocialSecurityValue.Text = currentCitizen.SocialSecurity.ToString();
                NameValue.Text = currentCitizen.Name.ToString();
                NameValue.NavigateUrl = "/Doctor/Patient.aspx?citizenId=" + currentCitizen.CitizenId;
                TimeCreatedValue.Text = currentCitizen.TimeCreated.ToString();
        //        PhoneValue.Text = currentCitizen.Phone.ToString();
        //        EmailValue.Text = currentCitizen.Email.ToString();
        //        PassKeyValue.Text = currentCitizen.PassKey.ToString();

                int eventId = int.Parse(Request["eventId"]);

                Event currentEvent = currentCitizen.Events.Single(x => x.EventId == eventId);

           
                GpContext gp = new GpContext();

                GridView3.DataSource = gp.Weights.Where(x => x.EventId == currentEvent.EventId).ToList();
                GridView3.DataBind();

                GridView1.DataSource = gp.Oximeters.Where(x => x.EventId == currentEvent.EventId).ToList();
                GridView1.DataBind();

                GridView2.DataSource = gp.Ecgs.Where(x => x.EventId == currentEvent.EventId).ToList();
                GridView2.DataBind();

                GridView4.DataSource = gp.BloodPressures.Where(x => x.EventId == currentEvent.EventId).ToList();
                GridView4.DataBind();


            }
        }

        protected void grantaccessBut_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Doctor/GrantAccess.aspx?CitizenID=" + Request["citizenID"]);
        }

    }
}